/*快速排序
 *
 */
#include "quicksort.h"
#include "swap.h"

int partition(int *array,int low,int high){
    if(array==NULL)
        return -1;
    //最好取随机值
    int key=array[low];

    while(low!=high){
        while(low<high && key<=array[high])
            high--;
        swap(array,low,high);
        while(low<high && array[low]<=key)
            low++;
        swap(array,low,high);
    }
    return low;
}

void quicksort(int *array,int low,int high){
    //下面的判断条件为啥不行
    //    if(high-low<2)
    //        return;
    if(array==NULL)
        return;

    if(low<high){
        int mid=partition(array,low,high);
        quicksort(array,low,mid-1);
        quicksort(array,mid+1,high);
    }
}
